home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / BTCONFIG.C < prev    next >
Text File  |  1988-11-29  |  12KB  |  412 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------            KopyRong (K) 1987.  ALL RIGHTS REVERSED.       */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*               This module was written by Vince Perriello                 */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*                  BinkleyTerm Configuration File Parser                   */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*   This  software  package is being distributed WITH FULL SOURCE CODE     */
  18. /*   with the  following  conditions:    1)  If  anything awful happens     */
  19. /*   because  you  use    it   (or  don't  use  it),  you  accept  full     */
  20. /*   responsibility;  2) you  don't start making tons of voice calls to     */
  21. /*   the authors to complain or  make  suggestions  about enhancements,     */
  22. /*   useful or otherwise;  3) you  do not reuse this code in commercial     */
  23. /*   products without specific permission to do so  from  the  authors;     */
  24. /*   4) If you find any problems you send  fixes  to  the  authors  for     */
  25. /*   inclusion  in  updates;    5) You find some way  to  express  your     */
  26. /*   appreciation  for  this  method of distribution, either by writing     */
  27. /*   code or  application  notes,  or  just sending along a "Thank You"     */
  28. /*   message.                                                               */
  29. /*                                                                          */
  30. /*   There is  copyrighted  code  in  this product.  We either wrote it     */
  31. /*   ourselves or got  permission  to use it.  Please don't force us to     */
  32. /*   pay a lawyer --  have some respect for our motives and don't abuse     */
  33. /*   this "license".                                                        */
  34. /*                                                                          */
  35. /*                                                                          */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. #include <stdio.h>
  39. #include <signal.h>
  40. #include <ctype.h>
  41. #include <conio.h>
  42. #include "com.h"
  43. #include "xfer.h"
  44.  
  45. extern int port_ptr;                /* and the port spec         */
  46. extern struct pointers ctl;            /* where the CD mask is      */
  47.  
  48. extern char boss_net,boss_node;            /* host node number in list  */
  49. extern char no_pickup;
  50. extern char no_requests;
  51. extern int  n_requests;
  52. extern int  baud;
  53. extern int lock_baud;
  54. extern int un_attended;
  55. extern int small_window;
  56. extern int no_overdrive;
  57. extern int fullscreen;
  58. extern int autobaud;
  59. extern int command_line_un;
  60. extern int overwrite;
  61. extern int loglevel;
  62. extern int slowmodem;
  63. extern int BBStimeout;
  64. extern char *BBSopt;                /* BBS option               */
  65. extern char *BBSbanner;                /* Banner to show if called */
  66. extern char *BBSreader;       /* Message reader to invoke */
  67. extern char *BOSSphone;       /* Boss phone number */
  68. extern char *BINKpath;
  69. FILE *status_log = NULL;
  70. int num_addrs = 1;
  71.  
  72. parse_config()
  73. {
  74. FILE *stream;
  75. char temp[256];
  76. char *c, *ctl_string();
  77. char *skip_blanks();
  78. char *config_file = "Binkley.Cfg";
  79. int i;
  80.  
  81. sprintf (temp, "%s%s", BINKpath, config_file);
  82. if ((stream = fopen(temp,"r")) == NULL)        /* OK, let's open the file   */
  83.     return(0);                /* no file, no work to do    */
  84.  
  85. while((fgets(temp,255,stream)) != NULL)        /* Now we parse the file ... */
  86.     {
  87.     c = temp;                /* Check out the first char  */
  88.     if ((*c == '%') || (*c == ';'))        /* See if it's a comment line*/
  89.         continue;
  90.  
  91.     i = strlen(temp);            /* how long this line is     */
  92.  
  93.    if (i < 3)
  94.       continue;
  95.  
  96.     c = &temp[--i];                /* point at last character   */
  97.     if (*c == '\n')                /* if it's a newline,        */
  98.         *c = '\0';            /* strip it off              */
  99.  
  100.  
  101.     if (strnicmp(temp,"overwrite",9) == 0)    /* Overwrite existing files     */
  102.         {
  103.       overwrite = 1;
  104.         continue;
  105.         }
  106.  
  107.     if (strnicmp(temp,"lockbaud",8) == 0)    /* Keep baud rate always locked */
  108.         {
  109.       lock_baud = 1;
  110.         continue;
  111.         }
  112.  
  113.     if (strnicmp(temp,"event",5) == 0)    /* Events to be executed     */
  114.         {
  115.         c = skip_blanks(&temp[5]);
  116.                 parse_event (c);
  117.         continue;
  118.         }
  119.  
  120.     if (strnicmp(temp,"zone",4) == 0)    /* Zone we are in            */
  121.         {
  122.         c = skip_blanks(&temp[4]);
  123.         ctl.our_zone = atoi(c);
  124.         if (!ctl.our_zone)        /* if we didn't find a zone  */
  125.         printf("Illegal zone: %s\n", &temp[4]);
  126.         continue;
  127.         }
  128.  
  129.    if (strnicmp(temp,"timeout",7) == 0)   /* How long before timeout to BBS */
  130.       {
  131.         c = skip_blanks(&temp[7]);
  132.         BBStimeout = atoi(c) * 100;
  133.         continue;
  134.       }
  135.  
  136.     if (strnicmp(temp,"maxreq",6) == 0)    /* Maximum number of requests */
  137.         {
  138.         c = skip_blanks(&temp[6]);
  139.         n_requests = atoi(c);
  140.         if (!n_requests)     /* No requests??? */
  141.             printf ("0 requests allowed\n");
  142.         continue;
  143.         }
  144.  
  145.     if (strnicmp(temp,"noslo",5) == 0)    /* No SLO stuff           */
  146.         {
  147.         no_overdrive = 1;
  148.         continue;
  149.         }
  150.  
  151.     if (strnicmp(temp,"slowmodem",9) == 0)    /* Modem reacts slowly    */
  152.         {
  153.         slowmodem = 1;
  154.         continue;
  155.         }
  156.  
  157.     if (strnicmp(temp,"smallwindow",11) == 0)    /* Small SEAlink windows  */
  158.         {
  159.         small_window = 1;
  160.         continue;
  161.         }
  162.  
  163.     if (strnicmp(temp,"nopickup",8) == 0)    /* No FTSC pickup           */
  164.         {
  165.         no_pickup = 1;
  166.         continue;
  167.         }
  168.  
  169.     if (strnicmp(temp,"norequests",10) == 0)    /* No SEAdog file requests  */
  170.         {
  171.         no_requests = 1;
  172.         continue;
  173.         }
  174.  
  175.     if (strnicmp(temp,"loglevel",8) == 0)    /* Level of logging to do    */
  176.         {
  177.         c = skip_blanks(&temp[8]);
  178.         i = atoi(c);
  179.       if ((i <= 5) && (i > 0))
  180.          {
  181.          loglevel = i;
  182.          }
  183.       else
  184.          {
  185.          printf ("LogLevel must be 1-5 - %s is unknown\n", &temp[8]);
  186.          }
  187.         continue;
  188.         }
  189.  
  190.     if (strnicmp(temp,"baud",4) == 0)    /* if this is a BAUD rate    */
  191.         {
  192.       ctl.max_baud = atoi (&temp[4]);
  193.         continue;
  194.         }
  195.  
  196.     if (strnicmp(temp,"port",4) == 0)    /* if this is a PORT spec    */
  197.         {
  198.         c = skip_blanks(&temp[4]);
  199.         i = atoi(c);            /* make it binary            */
  200.         if ((i == 1) || (i == 2))    /* see if it's OK            */
  201.             port_ptr = i - 1;    /* store it if so            */
  202.         else
  203.             printf("Illegal port: %s\n",&temp[4]);
  204.         continue;
  205.         }
  206.  
  207.     if (strnicmp(temp,"carrier",7) == 0)    /* if this is a CARRIER spec */
  208.         {
  209.         c = skip_blanks(&temp[7]);
  210.         i = 0;
  211.         sscanf(c,"%x",&i);        /* convert it to binary      */
  212.         if (i != 0)            /* if we got anything        */
  213.             ctl.carrier_mask = i;
  214.         else
  215.             printf("Invalid CARRIER mask: %s\n",&temp[7]);
  216.         continue;
  217.         }
  218.  
  219.     if (strnicmp(temp,"statuslog",9) == 0)    /* Log file for status messages */
  220.         {
  221.         ctl.log_name = ctl_string(&temp[9]);
  222.         if ((status_log = fopen (ctl.log_name, "aa")) == NULL)
  223.             {
  224.             free (ctl.log_name);
  225.             ctl.log_name = NULL;
  226.             }
  227.       else
  228.          {
  229.          fprintf (status_log, "\n");
  230.          real_flush (fileno (status_log));
  231.          }
  232.         continue;
  233.         }
  234.  
  235.    if (strnicmp(temp,"reader",6) == 0) /* Message reader to invoke (Alt-M) */
  236.       {
  237.       BBSreader = ctl_string (&temp[6]);
  238.       continue;
  239.       }
  240.  
  241.    if (strnicmp(temp,"bossphone",9) == 0) /* Boss's phone number */
  242.       {
  243.       BOSSphone = ctl_string (&temp[9]);
  244.       continue;
  245.       }
  246.  
  247.     if (strnicmp(temp,"system",6) == 0)    /* if this is system name    */
  248.         {
  249.         ctl.system_name = ctl_string(&temp[6]);
  250.         continue;
  251.         }
  252.  
  253.     if (strnicmp(temp,"sysop",5) == 0)    /* if this is my name        */
  254.         {
  255.         ctl.sysop = ctl_string(&temp[5]);
  256.         continue;
  257.         }
  258.  
  259.     if (strnicmp(temp,"boss",4) == 0)    /* if this is my boss name   */
  260.         {
  261.         c = skip_blanks(&temp[4]);
  262.         sscanf(c,"%d/%d",&boss_net,&boss_node);
  263.         continue;
  264.         }
  265.  
  266.     if (strnicmp(temp,"point",5) == 0)    /* if this is my point name  */
  267.         {
  268.         c = skip_blanks(&temp[5]);
  269.         sscanf(c,"%d/%d",&ctl.alias[0].net,&ctl.alias[0].node);
  270.         continue;
  271.         }
  272.  
  273.     if (strnicmp(temp,"aka",3) == 0)    /* if this is an aka for me  */
  274.         {
  275.         c = skip_blanks(&temp[3]);
  276.         sscanf(c,"%d/%d",&ctl.alias[num_addrs].net,&ctl.alias[num_addrs].node);
  277.       ++num_addrs;
  278.         continue;
  279.         }
  280.  
  281.     if (strnicmp(temp,"hold",4) == 0)    /* matrix hold area          */
  282.         {
  283.         ctl.hold_area = ctl_string(&temp[4]);
  284.         continue;
  285.         }
  286.  
  287.     if (strnicmp(temp,"netfile",7) == 0)    /* inbound file area         */
  288.         {
  289.         ctl.filepath = ctl_string(&temp[7]);
  290.         continue;
  291.         }
  292.  
  293.     if (strnicmp(temp,"netmail",7) == 0)    /* matrix message area       */
  294.         {
  295.         continue;            /* for BTCTL & MAIL.SYS      */
  296.         }
  297.  
  298.     if (strnicmp(temp,"init",4) == 0)    /* Modem init string         */
  299.         {
  300.         ctl.m_init = ctl_string(&temp[4]);
  301.         continue;
  302.         }
  303.  
  304.     if (strnicmp(temp,"busy",4) == 0)    /* Modem busy string         */
  305.         {
  306.         ctl.m_busy = ctl_string(&temp[4]);
  307.         continue;
  308.         }
  309.  
  310.     if (strnicmp(temp,"prefix",6) == 0)    /* if this is the dial prefix*/
  311.         {
  312.         ctl.predial = ctl_string(&temp[6]);
  313.         continue;
  314.         }
  315.  
  316.     if (strnicmp(temp,"suffix",6) == 0)    /* if this is the dial suffix*/
  317.         {
  318.         ctl.postdial  = ctl_string(&temp[6]);
  319.         continue;
  320.         }
  321.  
  322.     if (strnicmp(temp,"nodelist",8) == 0)    /* if a nodelist spec,       */
  323.         {
  324.         ctl.net_info = ctl_string(&temp[8]);
  325.         continue;
  326.         }
  327.  
  328.     if (strnicmp(temp,"avail",5) == 0)    /* if "AVAIL" file,          */
  329.         {
  330.         ctl.avail_list = ctl_string(&temp[5]);
  331.         continue;
  332.         }
  333.  
  334.  
  335.     if (strnicmp(temp,"okfile",6) == 0)    /* if F/R candidate list,    */
  336.         {
  337.         ctl.request_list = ctl_string(&temp[6]);
  338.         continue;
  339.         }
  340.  
  341.  
  342.     if (strnicmp(temp,"about",5) == 0)    /* if "ABOUT" file,          */
  343.         {
  344.         ctl.freq_about = ctl_string(&temp[5]);
  345.         continue;
  346.         }
  347.  
  348.     if (strnicmp(temp,"bbs",3) == 0)    /* if "BBS" line,            */
  349.         {
  350.         BBSopt = ctl_string(&temp[3]);
  351.         continue;
  352.         }
  353.  
  354.     if (strnicmp(temp,"banner",6) == 0)    /* if "BANNER" line,         */
  355.         {
  356.         BBSbanner = ctl_string(&temp[6]);
  357.         continue;
  358.         }
  359.  
  360.     if (strnicmp(temp,"unattended",10) == 0)    /* if unattended mode        */
  361.         {
  362.       un_attended = 1;
  363.       command_line_un = 1;
  364.         continue;
  365.         }
  366.  
  367.    if (strnicmp(temp,"nofullscreen",12) == 0)  /* Full screen mode off */
  368.       {
  369.       fullscreen = 0;
  370.       continue;
  371.       }
  372.  
  373.    if (strnicmp(temp,"autobaud",8) == 0)  /* Use highest baud when dialing */
  374.       {
  375.       autobaud = 1;
  376.       continue;
  377.       }
  378.  
  379.     printf("Unknown config line: %s\n",temp);
  380.     }
  381. fclose(stream);                    /* close input file          */
  382.  
  383. if (ctl.m_init == NULL)
  384. {
  385.    ctl.m_init = ctl_string ("|AT|");
  386. }
  387. if (ctl.m_busy == NULL)
  388. {
  389.    ctl.m_busy = ctl_string ("|AT|");
  390. }
  391. }
  392.  
  393. char *ctl_string(source)            /* malloc & copy to ctl      */
  394. char *source;
  395. {
  396. char *malloc();
  397. char *dest, *c;
  398. c = skip_blanks(source);            /* get over the blanks       */
  399. dest = malloc(strlen(c)+1);            /* allocate space for string */
  400. strcpy(dest,c);                    /* copy the stuff over       */
  401. return(dest);                    /* and return the address    */
  402. }
  403.  
  404.  
  405. char *skip_blanks(string)
  406. char *string;
  407. {
  408. while (*string && isspace (*string))
  409.     ++string;
  410. return(string);
  411. }
  412.